home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 113 / gfatip05 / gfatip05.txt < prev    next >
Text File  |  1987-11-28  |  6KB  |  122 lines

  1.  
  2.  
  3.                                                   June 14,1987
  4.  
  5.  
  6.                            GFATIP05.DOC
  7.  
  8.                         by John B. Holder
  9.                      Senior Software Engineer
  10.                      Marathon Computer Press
  11.            Asst. Sysop on GEnie's MichTron Roundtable
  12.  
  13.  
  14.                USING THE EXEC COMMAND IN GFA BASIC
  15.  
  16.      This is the fifth in a planned series by this author on 
  17. getting the most out of your GFA Basic Investment.  In this Tip 
  18. file we will briefly cover the EXEC command and some of it's 
  19. possibilities and peculiarities.
  20.  
  21.      There are several possibilities with this command, however I 
  22. will brush on just a few.  With the EXEC command you can either 
  23. load and execute or load and wait for a subsequent execution time.  
  24. Since the upcoming book by GFA Systemtechnik will go into detail 
  25. of how to load a program and execute it on call, I will skip over 
  26. that option.  The immediate load and go is the most common usage 
  27. of the EXEC command so that will be the mode discussed in this doc 
  28. file and in the GFATIP05.BAS and GFATIP51.BAS files.
  29.  
  30.      1. To simply load a program and execute it from a running 
  31. application we would do something like this:
  32.  
  33.                     Reserve Fre(0)-Spaceneeded
  34.                     Exec 0,"Your.Prg","",""
  35.  
  36.      Now you may ask how much is needed?  Well, you must reserve 
  37. enough for the entire program you are loading to fit into a block 
  38. of memory & you must also allow enough room for it's stack and 
  39. data storage area as well.  This is a process of dynamic memory 
  40. allocation for your called program.  So now you might ask, what is 
  41. the point that I start at?  How much do I give it?  Well, once 
  42. again you have to experiment a bit here to find just the right 
  43. amount.  Start out a little higher than you think you need first, 
  44. and then run your basic program and work the reserved memory down 
  45. until you have the minimum required to execute it successfully.  
  46. If you have not allocated enough memory the load and go will fail, 
  47. and the program will not run.  In that case, just allocate more 
  48. memory and try a run again.
  49.      Now once you have successfully accomplished the allocation of 
  50. memory and the execution of your called program, YOU MUST return 
  51. the memory to the memory pool by doing this:
  52.  
  53.                   Reserve Fre(0)+Spaceneeded-255
  54.  
  55.      If you do not return the memory, it will be retained by the 
  56. system and will continue to reduce itself if the program is called 
  57. repeatedly.  Not only that, the parent program will not have the 
  58. memory resource following the return of control without the 
  59. restoration function mentioned above.  The GFATIP05.BAS and 
  60. GFATIP51.BAS files will show you how this MUST be done.
  61.  
  62. 2. Other Possibilities:
  63.  
  64.      If you would like to call a TTP program and pass in a command 
  65. to it you must use the following calling convention:
  66.  
  67.  
  68.                       Suppose the command is 
  69.                          ah new.arc *.bas
  70.                           (For ARC.TTP)
  71.  
  72.                     Command$="ah new.arc *.bas"
  73.                     Command_length=Len(Command$)
  74.                     Command$=Chr$(Command_length)+Command$+Chr$(0)
  75.                     Reserve Fre(0)-Spaceneeded
  76.                     Exec 0,"Your.Prg",Command$,""
  77.                     Reserve Fre(0)+Spaceneeded-255
  78.  
  79.      That's all there is to it.  Essentially, what we did was 
  80. formulate a command in our mind (it must be a legal one for the 
  81. program you are passing it to), place the command into a string 
  82. variable, find out the length of the string, reconstruct the 
  83. command as this:
  84.  
  85.   Length of the command, Actual Command, A null Byte for Padding
  86.  
  87.      Other than that, the format is the same as that which the 
  88. other flavor of EXEC command uses.
  89.  
  90.  
  91. 3. Peculiarities:
  92.  
  93.      If you are calling a compiled GFA Basic program from a parent 
  94. interpreted Basic program, many times following the return from 
  95. the child (compiled basic program you called), you will be 
  96. presented with an alert box asking if you would like to continue 
  97. or quit.  This is because the compiled GFA Basic program is 
  98. passing the interpreted program a signal that says "Let's end".  
  99. It is sort of like pressing the Control+Shift+Alternate keys.  
  100. This peculiarity goes away if you compile the program.  In other 
  101. words, if all of your programs are compiled (Parent, and Child), 
  102. then you will not have this problem.  This is not a problem if you 
  103. don't mind having your program interrupted during development.  
  104.      Now you see why I have included a Demo Program written in 
  105. Modula 2 for an example.  This way those of you using Interpreters 
  106. only can run the GFATIP05.BAS file without interruption.  Since 
  107. Modula 2 uses a different exiting sequence, this "Break" does not 
  108. arise.
  109.  
  110.      To see the Break example run GFATIP51.BAS.  You will see the 
  111. difference as ICON.PRG is a compiled GFA Basic program.  The Icon 
  112. Demo came from the GFA Basic Companion's Source Code Libraries.  
  113. The GFA Basic Companion will be available at a Software Dealer 
  114. near you or directly from MichTron soon.
  115.  
  116.      I hope this helps many of you out.  If you are interested in 
  117. getting some questions answered on a live basis, why not stop in 
  118. for one of our weekly GFA Basic Conferences on GEnie at 10:00PM  
  119. EST, 7:00PM PST every Saturday.  A lot of GFA Experts and 
  120. Enthusiasts stop by each week.  We'll be looking for you.
  121.  
  122.